<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title>商品修改</title>
   <meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
 <link rel="stylesheet" type="text/css" href="__APP__/statics/css/style.css" />
 <script src="__APP__/statics/jquery-1.9.1.min.js" type="text/javascript"></script>
 <script type="text/javascript" charset="utf-8">window.UEDITOR_HOME_URL= "__PUBLIC__/ueditor/";</script>
 <script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/editor_config.js"></script>
 <script type="text/javascript" charset="utf-8" src="__PUBLIC__/ueditor/editor_all.js"></script>
<script type="text/javascript" src="__APP__/statics/jquery.form.js"></script>


<style type="text/css">
input{height:15px;padding:5px;}
#maintb{border:0;margin:0 auto;width:70%;border-style: solid; border-width: 2px; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px;border-color:#CCCCCC;}
#maintb input{size:20}
#pictb{border:0 ;width:100%;border-collapse: collapse; border-style: solid; border-width: 2px; padding-left: 4px; padding-right: 4px; padding-top: 1px; padding-bottom: 1px;border-color:#CCCCCC;}
#pictb td{height:30px;}
#nor_pic{height:30px;}

/*封面选择*/
.catt img{width:55px;border:0}
.catt a {border:#c8c9cd 1px solid;text-align:center;background-color:#fff;margin-left:5px;margin-top:6px;display:block;white-space:nowrap;color:#000;text-decoration:none;float:left;padding:7px}
.catt a:hover {border:#ff6701 2px solid;margin:-1px;margin-left:4px;margin-top:5px;}
.catt a:focus {outline-style:none;}
.catt .cattsel {border:#ff6701 2px solid;margin:-1px;background:url("__APP__/statics/choose_bg.jpg") no-repeat bottom right;margin-left:4px;margin-top:5px;}
.catt .cattsel a:hover {border:#ff6701 2px solid;margin:-1px;background:url("__APP__/statics/choose_bg.jpg") no-repeat bottom right;}
.catt input{display:none}
/*封面选择end*/
</style>
</head>
<body>

<h2>商品修改</h2>

<hr>


<form id="goods" method="POST" action="__URL__/save" enctype="multipart/form-data">
	<table id="maintb">
		<tr>
			<td align="right" colspan="3">
			<p align="left"><b><font style="font-size: 20pt">基本信息</font></b></td>
		</tr>
		<tr>
			<td width="11%" align="right" bgcolor="#E2E8EB">商品分类：</td>
			<td width="55%"><select size="1" id="goods_cat" name="goods_cat">
            <option value=''>-选择商品分类-</option>
<?php if(is_array($goods_cat)): $i = 0; $__LIST__ = $goods_cat;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$cat): $mod = ($i % 2 );++$i; if($cat["cat_id"] == $goods[cat_id]): ?><option value="<?php echo ($cat["cat_id"]); ?>" selected><?php echo ($cat["fullname"]); ?></option>
	    <?php else: ?>
           <option value="<?php echo ($cat["cat_id"]); ?>"><?php echo ($cat["fullname"]); ?></option><?php endif; endforeach; endif; else: echo "" ;endif; ?>
			</select></td>
			<td width="50%" rowspan="12" valign=top>
<!--商品图片start-->
				<table  id="pictb">
					<tr><td height="40"><b><font size="4">商品图片：</font></b></td></tr>
					<tr><td>
                        <div class="catt">
<?php if(is_array($pic)): $i = 0; $__LIST__ = $pic;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$pic): $mod = ($i % 4 );++$i; if($pic["s_pic"] == $goods['s_pic']): ?><a class="cattsel" onclick="changeAtt(this)" ondblclick="del_opic(this)" href="javascript:;"><img src="__APP__/<?php echo ($pic["s_pic"]); ?>" /><input name="o_pic" type="radio" value="<?php echo ($pic["pic_id"]); ?>" checked/></a>
<?php else: ?>
                     <a onclick="changeAtt(this)" ondblclick="del_opic(this)" href="javascript:;"><img src="__APP__/<?php echo ($pic["s_pic"]); ?>" /><input name="o_pic" type="radio" value="<?php echo ($pic["pic_id"]); ?>"/></a><?php endif; ?>
<?php if(($mod) == "3"): ?><div style="clear:both"></div><?php endif; endforeach; endif; else: echo "" ;endif; ?>						
						</div>
						</td>
					</tr>
					<tr><td><input style="height:30px" type="button" value="再添加一张…" id="add_pic"></td></tr>
					<tr><td id="n_pic"></td></tr>
				</table>
<!--商品图片end-->
			</td>
		</tr>
		<tr>
			<td width="11%" align="right" bgcolor="#E2E8EB">所属店铺：</td>
			<td width="55%">
				<select name="shop_id">
					<option value="0" <?php if($goods["shop_id"] == 0): ?>selected<?php endif; ?>>自营</option>
<?php if(is_array($shop_list)): $i = 0; $__LIST__ = $shop_list;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$shop): $mod = ($i % 2 );++$i;?><option value="<?php echo ($shop["shop_id"]); ?>" <?php if($goods["shop_id"] == $shop['shop_id']): ?>selected<?php endif; ?>><?php echo ($shop["shop_name"]); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
				</select>
				<font color="#FF0000" size="3">*</font>
			</td>
		</tr>
		<tr>
			<td width="11%" align="right" bgcolor="#E2E8EB">商品名称：</td>
			<td width="55%">
			<input type="text" name="goods_name" size="35" value="<?php echo ($goods["goods_name"]); ?>">
			<input type="text" name="goods_id" style="display:none" value="<?php echo ($goods["goods_id"]); ?>">
			<font color="#FF0000" size="3">*</font>
			</td>
		</tr>
		<tr>
			<td width="11%" align="right" bgcolor="#E2E8EB">商品品牌：</td>
			<td width="55%"><select size="1" name="goods_brand">
			<option value="">选择品牌</option>
<?php if(is_array($goods_brand)): $i = 0; $__LIST__ = $goods_brand;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$goods_brand): $mod = ($i % 2 );++$i; if($goods_brand["brand_id"] == $goods[goods_brand]): ?><option value="<?php echo ($goods_brand["brand_id"]); ?>" selected><?php echo ($goods_brand["brand_name"]); ?></option>
  <?php else: ?>
           <option value="<?php echo ($goods_brand["brand_id"]); ?>"><?php echo ($goods_brand["brand_name"]); ?></option><?php endif; endforeach; endif; else: echo "" ;endif; ?>
			</select></td>
		</tr>
		<tr>
			<td width="11%" align="right" bgcolor="#E2E8EB">商品编号：</td>
			<td width="55%">
			<input type="text" id="goods_bn" name="goods_bn" value="<?php echo ($goods["bn"]); ?>"><div id="check_bn"></div>
			</td>
		</tr>
		<tr>
			<td width="11%" align="right" bgcolor="#E2E8EB">计量单位：</td>
			<td width="55%"><input type="text" name="goods_unit" value="<?php echo ($goods["unit"]); ?>"></td>
		</tr>
		<tr>
			<td width="11%" align="right" bgcolor="#E2E8EB">简介：</td>
			<td width="55%"><textarea rows="5" name="s_intro" cols="31"> <?php echo ($goods["s_intro"]); ?></textarea></td>
		</tr>
		<tr>
			<td width="11%" align="right" bgcolor="#E2E8EB">是否上架：</td>
			<td width="55%">
<?php if($goods["is_post"] == '0' ): ?><input type="radio" value="0" name="is_post" checked>是
			<input type="radio" value="1" name="is_post">否</td>
<?php else: ?>
            <input type="radio" value="0" name="is_post">是 
			<input type="radio" value="1" name="is_post" checked>否</td><?php endif; ?>
		</tr>
		<tr>
			<td width="11%" align="right" bgcolor="#E2E8EB">销售价：</td>
			<td width="55%"><input type="text" name="goods_price" value="<?php echo ($goods["price"]); ?>"></td>
		</tr>
		<tr>
			<td width="11%" align="right" bgcolor="#E2E8EB">成本价：</td>
			<td width="55%"><input type="text" name="goods_cost" value="<?php echo ($goods["cost"]); ?>"></td>
		</tr>
		<tr>
			<td width="11%" align="right" bgcolor="#E2E8EB">市场价：</td>
			<td width="55%"><input type="text" name="mktprice" value="<?php echo ($goods["market_price"]); ?>"></td>
		</tr>
		<tr>
			<td width="11%" align="right" bgcolor="#E2E8EB">重量：</td>
			<td width="55%"><input type="text" name="goods_weight" value="<?php echo ($goods["weight"]); ?>"></td>
		</tr>
		<tr>
			<td width="11%" align="right" bgcolor="#E2E8EB">库存：</td>
			<td width="55%"><input type="text" name="goods_store"  value="<?php echo ($goods["store"]); ?>"></td>
		</tr>
		<tr>
			<td width="11%" align="right" bgcolor="#E2E8EB">货位：</td>
			<td width="55%"><select size="1" name="goods_place">
			<option value="a">选择货位</option>
<?php if(is_array($goods_place)): $i = 0; $__LIST__ = $goods_place;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$goods_place): $mod = ($i % 2 );++$i; if($goods_place["place_id"] == $goods[store_place]): ?><option value="<?php echo ($goods_place["place_id"]); ?>" selected>
	<?php if($goods_place["parent"] == '0' ): echo ($goods_place["place_name"]); ?>
		<?php else: ?>
		       &nbsp;&nbsp;|­­ <?php echo ($goods_place["place_name"]); endif; ?>
			</option>
<?php else: ?>
            <option value="<?php echo ($goods_place["place_id"]); ?>">
	<?php if($goods_place["parent"] == '0' ): echo ($goods_place["place_name"]); ?>
		<?php else: ?>
		       &nbsp;&nbsp;|­­ <?php echo ($goods_place["place_name"]); endif; ?>
			</option><?php endif; endforeach; endif; else: echo "" ;endif; ?>
			</select></td>
		</tr>
	</table>
	<br>
	<table id="maintb">
		<tr>
			<td><span style="font-size: 20pt"><b>扩展属性</b></span></td>
		</tr>
		<tr>
			<td>
			   <div id="kuozhan">
			        <table border="0"  width="100%"  cellspacing="5" >
<?php if(is_array($pdt)): $i = 0; $__LIST__ = $pdt;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$pdt): $mod = ($i % 2 );++$i;?><tr>
							<td width="11%" align="right" bgcolor="#E2E8EB">
							    <input type="text" name='value_id[]' value="<?php echo ($pdt["pdt"]); ?>" style="display:none">
								<input type="text" name='kz_name[]' value="<?php echo ($pdt["kz_name"]); ?>" style="display:none"><?php echo ($pdt["kz_name"]); ?>：
							</td>
<?php if($pdt["type"] == 'a' ): ?><td><input type="text" name='kuozhan[]' value="<?php echo ($pdt["kuozhan"]); ?>"></td>
<?php else: ?>
                            <td><select name='kuozhan[]'>
					<?php if(is_array($pdt[key])): $i = 0; $__LIST__ = $pdt[key];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$keys): $mod = ($i % 2 );++$i; if($keys == $pdt['kuozhan']): ?><option  value="<?php echo ($keys); ?>" selected><?php echo ($keys); ?></option>
					<?php else: ?>
					        <option  value="<?php echo ($keys); ?>"><?php echo ($keys); ?></option><?php endif; endforeach; endif; else: echo "" ;endif; ?>
							</select>
							</td><?php endif; ?>
						</tr><?php endforeach; endif; else: echo "" ;endif; ?>
					</table>

			   </div>
			</td>
		</tr>
		</table>
	<br>
	<table id="maintb" name="p_guige">
		<tr>
			<td><span style="font-size: 20pt"><b>商品规格</b></span></td>
		</tr>

		<tr id="prop_title">
			<td>
			<input id="add_prop" type="button" style="height:30px" value="添加一个货品">
			<!--商品规格-->
                 <table border="0" width="100%" cellspacing="3" id="prop_n">
					<tr  bgcolor="#E2E8EB" align="center">
					
<?php if(is_array($prop_n)): $i = 0; $__LIST__ = $prop_n;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$prop_n): $mod = ($i % 2 );++$i;?><td>
					<input style="font-weight:800;font-size:14px;color:#0033CC;" type="text" name="prop_name[]" value="<?php echo ($prop_n); ?>">
					</td><?php endforeach; endif; else: echo "" ;endif; ?>
					<td>价格</td>
					<td>库存</td>
					</tr>
<?php if(is_array($product)): $i = 0; $__LIST__ = $product;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$product): $mod = ($i % 2 );++$i;?><tr align="center">
					
	<?php if(is_array($product['prop'])): $i = 0; $__LIST__ = $product['prop'];if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$prop): $mod = ($i % 2 );++$i;?><td>
			         <input type="text" name="prop<?php echo ($i); ?>[]" value="<?php echo ($prop); ?>">
			       </td><?php endforeach; endif; else: echo "" ;endif; ?>
	
					<td><input type="text" name="prop_price[]" value="<?php echo ($product["price"]); ?>"></td>
					<td><input type="text" name="prop_store[]" value="<?php echo ($product["store"]); ?>">

					 <input type="text" name="product_id[]" value="<?php echo ($product["product_id"]); ?>" style="display:none">
					<a href='javascript:;' name='del_prop' value="<?php echo ($product["product_id"]); ?>"><img alt="删除" src="__APP__/statics/btn-close.gif" border="0" /></a>
					</td>
					</tr><?php endforeach; endif; else: echo "" ;endif; ?>
					</table>
					<!--商品规格end-->
            </td>
		</tr>
		</table>
		
	<br>
	<table id="maintb">
		<tr>
			<td><span style="font-size: 20pt"><b>详细介绍</b></span></td>
		</tr>
		<tr>
			<td><textarea name="content" id="content"><?php echo ($goods["intro"]); ?></textarea></td>
		</tr>
	</table>
	<br>
	<table id="maintb">
		<tr>
			<td><span style="font-size: 20pt"><b>商品标签</b></span></td>
		</tr>
		<tr>
			<td>
            <select name="goods_label">
			   <option value="">无</option>
<?php if($goods["goods_label"] == 'hot'): ?><option value="hot" selected>热卖</option>
<?php else: ?>
			   <option value="hot">热卖</option><?php endif; ?>

<?php if($goods["goods_label"] == 'price'): ?><option value="price" selected>特价</option>
<?php else: ?>
			   <option value="price">特价</option><?php endif; ?>

<?php if($goods["goods_label"] == 'rec'): ?><option value="rec" selected>推荐</option>
<?php else: ?>
			   <option value="rec">推荐</option><?php endif; ?>
		   </select>
			</td>
		</tr>

		</table>


	<p align="center">
   <input type="submit" value="保存修改" id="send" style="padding:5px;height:50px;width:200px">
	<!--<input type="button" value="保存修改" name="save" style="padding:5px;height:50px;width:200px">-->
	</p>
</form>


<?php if($prop_num == '2'): ?><div style="display:none">
<table>
<tr align="center"  id="prop_z">
		<td><input type="text" name="prop1[]"  value=""></td>
		<td><input type="text" name="prop2[]" value=""></td>
		<td><input type="text" name="prop_price[]" value=""></td>
		<td><input type="text" name="prop_store[]" value="">
		<a href='javascript:;'  name='del_nprop'><img alt="删除" src="__APP__/statics/btn-close.gif" border="0"/></a></div></td>
</tr>
</table>
</div>
<?php elseif($prop_num == '1'): ?>
<div style="display:none">
<table>
<tr align="center"  id="prop_z">
		<td><input type="text" name="prop1[]"  value=""></td>
		<td><input type="text" name="prop_price[]" value=""></td>
		<td> <input type="text" name="prop_store[]" value="">
		<a href='javascript:;'  name='del_nprop'><img alt="删除" src="__APP__/statics/btn-close.gif" border="0"/></a></div></td>
</tr>
</table>
</div><?php endif; ?>

<div style="display:none">
<table>
            <tr name="y_prop">
			<td>
<?php if(is_array($goods_prop)): $i = 0; $__LIST__ = $goods_prop;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$goods_prop): $mod = ($i % 2 );++$i;?><input type="checkbox" id="prop_name" name="prop_name" value="<?php echo ($goods_prop["prop_name"]); ?>"><?php echo ($goods_prop["prop_name"]); endforeach; endif; else: echo "" ;endif; ?>
              <input type="button" id="choose_prop" value="生成所有商品">
			  如果不需要那么多留空即可
            </td>
		</tr>
		<tr name="y_prop">
			<td><div id="guige">请选择规格……</div></td>
		</tr>
</table>
</div>

<script type="text/javascript">
$(function(){
     var ck=$("[name='prop_name[]']").val();
     if(ck==undefined){
         ifClear();
     }

	 $("[name=save]").click(function(){
		var content=editor.getContent();
		$("[name=content]").val(content);
		$('#goods').ajaxSubmit({
		success:alert("修改成功")});// 提交表单
		return false;   //防止浏览器提交表单
   }); //ajax提交表单


      //增加input
      $("#add_pic").click(function(){
	          $("<div id='nor_pic'>相册:<input type='file' name='goods_pic[]' size='20'><a href='javascript:;' name='del_pic'><img alt='删除' src='__APP__/statics/btn-close.gif' border='0' /></a></div>").appendTo($("#n_pic"));
			  delPic();
	  })
      
	  //移除按钮
	  function delPic() {
	      $("a[name=del_pic]").unbind().click(function () {
          $(this).parent().remove();
	  })
	  }

	  $("#goods_bn").blur(function(){
	     var bn=$("#goods_bn").val();
		 $.ajax({
		     type:"GET",
			 url:"__URL__/check_bn",
			 dataType:"html",
			 data:{goods_bn:bn},
			 success:function(data){
				                $("#check_bn").html(data);
								}
			 })
	  })

	  //获取扩展属性
      $("#goods_cat").change(function(){
	          var cat=$("#goods_cat").val();
			  $.ajax({
			      type:"POST",
				  url:"__GROUP__/Goodsmodel/get_model_value",
				  dataType:"html",
				  data:{goods_cat:cat},
				  success:function(data){$("#kuozhan").html(data);}
				})
			  })

	  //获取规格
	  $("#choose_prop").click(function(){
	          var price=$("[name=goods_price]").val();
			  var store=$("[name=goods_store]").val();
	          var stra=[];
			  $("[name=prop_name]:checked").each(function(){
                     stra.push($(this).val()); 
               }); 

			   $.ajax({
			      type:"POST",
				  url:"__GROUP__/Goodsprop/prop_value",
				  dataType:"html",
				  data:{"goods_prop":stra,"price":price,"store":store},
				  success:function(data){$("#guige").html(data);}
				})
	  })

});
</script>

<script>
//删除规格
$("a[name=del_prop]").click(function(){
   var pro_id=$(this).prev().val();
   if(confirm('你确认删除此规格吗？删除后此规格商品的所有信息都将删除！')) {
       $.ajax({
	       type:"POST",
		   url:"__URL__/del_product",
		   dataType:"html",
		   data:{"pro_id":pro_id},
		   success:function(data){
               if(data=='1'){
				  jSuccess("<strong>删除成功!</strong>",{VerticalPosition : 'center',HorizontalPosition : 'center'});
			  }else{
			      jError("<strong>删除失败!请重试</strong>",{VerticalPosition : 'center',HorizontalPosition : 'center'});
			 }
		   }
	   })
	   $(this).parent().parent().remove();
	   ifClear();
   }
})
function ifClear(){
   var ck=$("[name='prop_name[]']").val();
   if(ck==undefined){
     $("#prop_title").remove();
     $("[name=p_guige]").append($("[name=y_prop]").clone(true));
   }
}
//移除新添加的规格
$("a[name=del_nprop]").click(function(){
  $(this).parent().parent().remove();
  ifClear();
})
function changeAtt(t) {
     t.lastChild.checked='checked';
     for (var i = 0; i<t.parentNode.childNodes.length;i++) {
            if (t.parentNode.childNodes[i].className == 'cattsel') {
                   t.parentNode.childNodes[i].className = '';
            }
      }
          t.className = "cattsel";
  }

  function del_opic(t){
  var pid=$("[name=o_pic]:checked").val();
   if(confirm('你确认要移除此图片吗？删除后不可恢复！')) {
      $.ajax({
	      type:"GET",
		  url:"__GROUP__/Goodspic/get_pic",
		  dataType:"html",
		  data:{pic_id:pid},
		  success:function(data){
		      if(data=='1'){
                   $("a[class=cattsel]").remove();
                   jSuccess("<strong>删除成功!</strong>",{VerticalPosition : 'center',HorizontalPosition : 'center'});
			  }else{
			       jError("<strong>删除失败，请重试!</strong>",{VerticalPosition : 'center',HorizontalPosition : 'center'});
			  }
		  }
		})
   }//confirm end
  }

  $("#add_prop").click(function(){$("#prop_n").append($("#prop_z").clone(true));})
</script>


<link rel="stylesheet" type="text/css" href="__APP__/statics/css/jNotify.jquery.css" />
<script type="text/javascript" src="__APP__/statics/jNotify.jquery.js"></script>
</body>
<SCRIPT type="text/javascript">  
    var editor = new UE.ui.Editor();  
    editor.render("content");  
</SCRIPT>
</html>